//
//  Untitled.swift
//  hello
//
//  Created by 赵康 on 2025/3/24.
//
import Vapor
import Fluent

final class Feedback: Model, Content, @unchecked Sendable {
  static var schema: String { SchemaEnum.feedbacks.rawValue }
  
  @ID(key: .id)
  var id: UUID?
  
  @Parent(key: FieldKeys.reporter)
  var reporter: User
  
  @Field(key: FieldKeys.category)
  var category: FeedbackCategory
  
  @Field(key: FieldKeys.type)
  var type: FeedbackType
  
  @Field(key: FieldKeys.content)
  var content: String?
  
  @Field(key: FieldKeys.status)
  var status: FeedbackStatus
  
    // 可选关联字段 - 使用 OptionalParent
  @OptionalParent(key: FieldKeys.audio)
  var audio: Audio?
  
  @OptionalParent(key: FieldKeys.transcript)
  var transcript: Transcript?
  
  @OptionalParent(key: FieldKeys.note)
  var note: Note?
  
  @Timestamp(key: FieldKeys.createdAt, on: .create)
  var createdAt: Date?
  
  @Timestamp(key: FieldKeys.updatedAt, on: .update)
  var updatedAt: Date?
  
    // 反馈分类枚举
  enum FeedbackCategory: String, Codable {
    case report = "report"           // 举报违规内容
    case contentIssue = "contentIssue" // 内容问题
    case technicalIssue = "technicalIssue" // 技术问题
    case suggestion = "suggestion"   // 功能建议
    case other = "other"             // 其他
  }
  
    // 反馈类型枚举
  enum FeedbackType: String, Codable {
      // 举报类型
    case political = "political"         // 政治反动内容
    case pornographic = "pornographic"   // 低俗色情内容
    case spam = "spam"                   // 垃圾广告信息
    case harassment = "harassment"       // 恶意攻击谩骂
    
      // 音频问题
    case audioQuality = "audioQuality"   // 音频质量问题
    case audioPlayback = "audioPlayback" // 播放问题
    
      // 字幕问题
    case spellingError = "spellingError"     // 单词拼写错误
    case translationError = "translationError" // 译文错误
    case timingIssue = "timingIssue"         // 时间轴有误
    case missingContent = "missingContent"   // 缺少内容
    case otherIssue = "otherIssue"           // 其他问题
    
      // 一般问题
    case appBug = "appBug"               // 应用程序错误
    case featureRequest = "featureRequest" // 功能请求
    case other = "other"                 // 其他问题
  }
  
    // 反馈状态枚举
  enum FeedbackStatus: String, Codable {
    case pending = "pending"       // 待处理
    case reviewing = "reviewing"   // 审核中
    case resolved = "resolved"     // 已解决
    case rejected = "rejected"     // 已驳回
  }
  
  init() { }
  
  init(
    id: UUID? = nil,
    reporterID: User.IDValue,
    category: FeedbackCategory,
    type: FeedbackType,
    content: String? = nil,
    status: FeedbackStatus = .pending,
    audioID: Audio.IDValue? = nil,
    transcriptID: Transcript.IDValue? = nil,
    noteID: Note.IDValue? = nil
  ) {
    self.id = id
    self.$reporter.id = reporterID
    self.category = category
    self.type = type
    self.content = content
    self.status = status
    self.$audio.id = audioID
    self.$transcript.id = transcriptID
    self.$note.id = noteID
  }
  
    // 创建反馈请求
  struct Create: Content {
    let category: FeedbackCategory
    let type: FeedbackType
    let content: String?
    let audioID: UUID?
    let transcriptID: UUID?
    let noteID: UUID?
  }
  
    // 反馈响应
  struct Response: Content {
    let id: UUID?
    let reporterID: UUID
    let category: FeedbackCategory
    let type: FeedbackType
    let content: String?
    let status: FeedbackStatus
    let audioID: UUID?
    let transcriptID: UUID?
    let noteID: UUID?
    let createdAt: Date?
    let updatedAt: Date?
  }
}
